import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:online_study/base/app_title.dart';
import 'package:online_study/mine/exam/answer_item.dart';
import 'package:online_study/mine/exam/exam_bean.dart';
import 'package:online_study/mine/exam/start_exam.dart';
import 'package:online_study/theme/colors.dart';
import 'package:online_study/theme/size.dart';

//考试结果(答题记录)
class ExamResultPage extends StatefulWidget {
  @override
  _ExamResultState createState() => _ExamResultState();
}

class _ExamResultState extends State<ExamResultPage> {
  List<ExamBean> _list = [];

  @override
  void initState() {
    super.initState();
    [1, 2, 3, 4, 5, 6, 7, 8, 9].forEach((element) {
      var examBean = ExamBean();
      if (element > 4) {
        examBean.isMulti = true;
        examBean.correctAnswers = ["A", "B", "C"];
        examBean.choiceAnswers = ["A"];
      } else {
        examBean.isMulti = false;
        examBean.correctAnswers = ["D"];
        examBean.choiceAnswers = ["D"];
      }
      examBean.question = "提升自身形象的三大要素";
      List<String> result = ["A . 肢体语言", "B . 着装", "C . 专业技能", "D . 过度饮酒"];
      examBean.answers = result;
      _list.add(examBean);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(color: ThemeColor.color333333),
        titleSpacing: 0,
        backgroundColor: ThemeColor.colorWhite,
        elevation: ThemeSize.appElevation,
        title: AppTitle("考试详情"),
      ),
      body: Column(
        children: [
          Expanded(
              child: ListView.separated(
                  itemBuilder: (BuildContext context, int index) {
                    var examBean = _list[index];
                    examBean.index = index + 1;
                    return AnswerItemPage(examBean);
                  },
                  separatorBuilder: (BuildContext context, int index) {
                    return Divider(height: ThemeSize.width1);
                  },
                  itemCount: _list.length)),
          Divider(height: ThemeSize.width1),
          Container(
            color: ThemeColor.colorWhite,
            alignment: Alignment.center,
            height: ThemeSize.height84,
            child: MaterialButton(
              height: ThemeSize.height36,
              color: ThemeColor.color1485EE,
              child: Text("重新考试",
                  style: TextStyle(
                      color: ThemeColor.colorWhite, fontSize: ThemeSize.sp16)),
              shape: RoundedRectangleBorder(
                  borderRadius:
                      BorderRadius.all(Radius.circular(ThemeSize.height18))),
              onPressed: () {
                Get.to(() => StartExamPage());
              },
            ),
          )
        ],
      ),
    );
  }
}
